﻿Partial Public Class WebFormKunde1
    Inherits System.Web.UI.Page
    Private bla As New ArrayList
    Public _db As New hc_databaseDataContext

    Public Artlist() As String




    Protected Sub KundeIDSession(ByVal ID As Integer)
        Session("KundeID") = ID

    End Sub

    Protected Sub MultivievUebersicht() Handles Me.Load

        lblUeberschrift.Text = "Übersicht: Kunden"

        '#######TEST
        'Session("Rang") = 2
        'Dim pr(,) As Integer = {{2, 2}, {3, 1}}
        'Session("Projekte_Rang") = pr

        '#######TEST



        Dim rang As Integer
        rang = Session("Rangid")

        'wenn der Nutzer ein PM oder VP ist
        If rang <= 2 Then

            GVKunden.DataSource = From K In _db.Kundes Select K.Name, K.Branche Order By name

        End If


        'wenn er  zur zeit Projekte macht

        Dim projekttab As New DataTable

        projekttab.Columns.Add("Name")
        projekttab.Columns.Add("Branche")

        Dim Projekte As List(Of Integer)


        Projekte = Session("Projekte_maud")




        Dim i As Integer
        For i = 0 To Projekte.Count - 1
            Try



                Dim proID As Integer = Projekte(i)
                Dim KundeIDVonProjekt As Integer = (From P In _db.Projekts Where P.ID = proID Select P.KundeID).First

                '  Dim arr() = (From K In _db.Kunde Where K.ID = KundeIDVonProjekt Select K.Name, K.Branche).ToArray

                Dim row(1) As String

                row(0) = (From K In _db.Kundes Where K.ID = KundeIDVonProjekt Select K.Name).First
                row(1) = (From K In _db.Kundes Where K.ID = KundeIDVonProjekt Select K.Branche).First

                bla.Add(KundeIDVonProjekt)


                projekttab.Rows.Add(row)


            Catch ex As Exception
                Exit For
            End Try

        Next




        GVKundenO.DataSource = projekttab
        GVKundenO.DataBind()

        Try
            GVKundenO.Columns.Item(1).ItemStyle.Font.Bold = True

        Catch ex As Exception

        End Try






        GVKunden.DataBind()



    End Sub


    Protected Sub GVKundenSelect() Handles GVKunden.SelectedIndexChanged
        'Dim index As Integer = GVKunden.SelectedIndex
        Dim kundenabfrage = (From K In _db.Kundes Select K.ID, K.Name Order By Name).ToList

        Dim KNummer = GVKunden.SelectedIndex
        Dim KID = kundenabfrage(KNummer).ID
        '  Dim KID As Integer = (From K In _db.Kundes Where K.Name = KName Select K.ID).First


        KundeIDSession(KID)
        Dim kundenname = (From K In _db.Kundes Where K.ID = KID Select K.Name).First

        ' Me.KundeIDSession(KID)


        '  TreeView1.Nodes.Item(1).Select()
        ' btnUebersicht_Click()
        'MultiView1.ActiveViewIndex = 1

        'MultiView2.ActiveViewIndex = 0
        Response.Redirect("WebFormDetails.aspx")

      
    End Sub

    Protected Sub GVKundenOSelect() Handles GVKundenO.SelectedIndexChanged
        Dim KNummer = GVKundenO.SelectedIndex
        Dim KID As Integer = bla(KNummer)
        Dim kundenname = (From K In _db.Kundes Where K.ID = KID Select K.Name).First

        KundeIDSession(KID)


        Response.Redirect("WebFormDetails.aspx")


    End Sub





    
   
    Protected Sub GVKundenSelect(ByVal sender As Object, ByVal e As EventArgs)

    End Sub
End Class